<?php
// +----------------------------------------------------------------------
// | 文章展示控制器详情页
// +----------------------------------------------------------------------
// | Author:  Eric <ieyangxiaoguo@126.com>
// +----------------------------------------------------------------------
// | Copyright ©2018  http://www.zzuyxg.top  All rights reserved.
// +----------------------------------------------------------------------
// | 2018年3月22日
// +----------------------------------------------------------------------
namespace app\index\controller;

use app\common\model\ArticleModel;
use app\common\model\FruitModel;
use app\common\model\MemberModel;
use app\common\model\QuestionsModel;
use app\common\model\RequirementModel;
use app\common\model\SpecialtyModel;
use app\common\model\TeacherModel;
use app\common\model\TeamMemberModel;
use app\common\model\TeamModel;
use app\index\validate\Team;
use think\Cookie;
use think\Db;

class MeController extends BaseController
{
    public function __construct()
    {
        $this->_initializeView();
        parent::__construct();
        if (session('uid')) {
            $user = json_decode(session('userInfo'), true);
            $this->assign('uid', session('uid'));
            $this->assign('user', $user);
        } else {
            $this->assign('uid', null);
            $this->assign('user', null);
            $this->redirect('login/login');
        }
    }


    public function me()
    {
        $user = json_decode(session('userInfo'), true);

        if ($user) {
            $issuer_type = isset($user['teacher_no']) ? 0 : 1;
            if ($issuer_type == 0) {
                $user = TeacherModel::with(['college_detail', 'specialty_detail'])->where('id', $user['id'])->find();
                $this->assign('tagList', explode(',', $user['tag_text']));
            } else {
                $user = MemberModel::where('id', $user['id'])->find();
            }
            $this->assign('user', $user);
            $this->assign('user_type', $issuer_type);

        } else {
            return $this->redirect('login/login');
        }

        if (is_mobile()) {
            return $this->fetch('/mobile/me/me');
        }
        return $this->fetch();
    }

    public function callme()
    {

        $config = get_option("site_info");
        $this->assign([
            'phone' => $config['phone'],
            'wechat' => $config['wechat'],
        ]);
        if (is_mobile()) {
            return $this->fetch('/mobile/me/callme');
        }
        return $this->fetch();
    }

    public function edit()
    {


        $user = json_decode(session('userInfo'), true);
        if ($user) {
            $issuer_type = isset($user['teacher_no']) ? 0 : 1;
            if ($issuer_type == 0) {
                $teacher = TeacherModel::with(['college_detail', 'specialty_detail'])->where('id', $user['id'])->find();
                $colleges = Db::name("college")->where("status", 1)
                    ->order("id asc")
                    ->all();
                $specialties = SpecialtyModel::where('college_id', $teacher['college'])->all();
                $tags = Db::query("select * from sk_tags where uid = ".$user['id']. " and type = 0 or user_type = 3 and type = 0");
                $this->assign("tagList", $tags);
                $this->assign("teacher", $teacher);
                $this->assign("colleges", $colleges);
                $this->assign('specialties', $specialties);
                $this->assign('user', $user);
                $this->assign('user_type', $issuer_type);
                if (is_mobile()) {
                    return $this->fetch('/mobile/me/edit_teacher');
                }
                return $this->fetch('edit_teacher');
            } else {
                $user = MemberModel::where('id', $user['id'])->find();
                $this->assign("member", $user);
                $this->assign('user', $user);
                $this->assign('user_type', $issuer_type);
                if (is_mobile()) {
                    return $this->fetch('/mobile/me/edit_member');
                }
                return $this->fetch('edit_member');
            }
        } else {
            return $this->redirect('login/login');
        }

    }


    public function saveTeacher()
    {
        if ($this->request->isPost()) {
            $data = $this->request->param();
            $image = $data['image'];
            $update = [
                'real_name' => $data['real_name'],
                'phone' => $data['phone'],
                'college' => $data['college'],
                'specialty' => $data['specialty'],
//                'tags' => $data['tags'],
                'tag_text' => $data['tag_text'],
                'resume' => $data['resume'],

            ];
            if (!empty($image)) {
                //$data = file_get_contents('./1.txt');
                $reg = '/data:image\/(\w+?);base64,(.+)$/si';
                preg_match($reg, $image, $match_result);
                if (count($match_result)) {
                    $file_name = time() . '.' . $match_result[1];

                    $logo_path = ROOT_PATH . '/upload/avatar/' . $file_name;
                    $update['head_img'] = '/upload/avatar/' . $file_name;
                    $num = file_put_contents($logo_path, base64_decode($match_result[2]));
                    if (!empty($num)) {
                        //上传成功之后，再进行缩放操作
                        $image = \think\Image::open($logo_path);
                        // 按照原图的比例生成一个最大为150*150的缩略图并保存为thumb.png
                        $image->thumb(120, 120)->save($logo_path);
                    }
                }
            }
            $id = cookie('uid');


            $result = TeacherModel::where('id', $id)->update($update);

            return [
                'code' => 0,
                'msg' => '保存成功',
                'result' => $result,
                'sql' => Db::getLastSql()
            ];
        }
    }


    public function saveMember()
    {
        if ($this->request->isPost()) {
            $user = json_decode(session('userInfo'), true);
            if ($user) {
                $issuer_type = isset($user['teacher_no']) ? 0 : 1;
                if ($issuer_type != 1) {
                    return [
                        'code' => 1,
                        'msg' => '无权操作',
                    ];
                }
                $data = $this->request->param();
                $image = $data['image'];
                $update = [
                    'real_name' => $data['real_name'],
                    'phone' => $data['phone'],
                    'company' => $data['company'],
                ];
                if (!empty($image)) {
                    //$data = file_get_contents('./1.txt');
                    $reg = '/data:image\/(\w+?);base64,(.+)$/si';
                    preg_match($reg, $image, $match_result);
                    if (count($match_result)) {
                        $file_name = time() . '.' . $match_result[1];

                        $logo_path = ROOT_PATH . '/upload/avatar/' . $file_name;
                        $update['head_img'] = '/upload/avatar/' . $file_name;
                        $num = file_put_contents($logo_path, base64_decode($match_result[2]));
                        if (!empty($num)) {
                            //上传成功之后，再进行缩放操作
                            $image = \think\Image::open($logo_path);
                            // 按照原图的比例生成一个最大为150*150的缩略图并保存为thumb.png
                            $image->thumb(120, 120)->save($logo_path);
                        }
                    }
                }
                $id = cookie('uid');
                $result = MemberModel::where('id', $id)->update($update);
            } else {
                return [
                    'code' => 1,
                    'msg' => '无权操作',
                ];
            }

            return [
                'code' => 0,
                'msg' => '保存成功',
                'result' => $result,
                'sql' => Db::getLastSql()
            ];
        }
    }


    public function addTag()
    {
        if ($this->request->isPost()) {
            $tag = $this->request->param('newTag');
            $find = Db::name("tags")->where("tag", $tag)->where('type', 0)->find();
            if ($find) {
                $data['code'] = 1;
                $data['msg'] = '已在该标签';
            } else {
                $user = json_decode(session('userInfo'), true);
                if ($user) {
                    $tid = Db::name("tags")->insertGetId(['tag' => $tag, 'type' => 0, 'uid' => $user['id'], 'user_type' => isset($user['teacher_no']) ? '0' : '1']);
                    $newTag = Db::name("tags")->where('id', $tid)->find();
                    $data['code'] = 0;
                    $data['msg'] = '成功';
                    $data['data'] = $newTag;
                    $data['tid'] = $tid;
                } else {
                    $data['code'] = 1;
                    $data['msg'] = '请先登录';
                    return $data;
                }


            }
            return $data;
        }
    }


    public function getSpecialties()
    {
        if ($this->request->isPost()) {
            $college_id = $this->request->param('college_id');
            if ($college_id) {
                $specialties = Db::name("specialty")->where('college_id', $college_id)->where('status', 1)->order('id asc')->all();
                $data['code'] = 0;
                $data['msg'] = '成功';
                $data['data'] = $specialties;
            } else {
                $data['code'] = 0;
                $data['msg'] = '成功';
                $data['data'] = [];
            }
            return $data;
        }
    }

    public function fruit()
    {

        $page = $this->request->param('page');
        $page = $page ? $page : 1;
        $user = json_decode(session('userInfo'), true);
        if (isset($user['teacher_no'])) {
            $type = 0;
        } else {
            $type = 1;
        }
        $count = FruitModel::where('issuer', $user['id'])->where('issuer_type', $type)->count();
        if (is_mobile()){
            $fruits = FruitModel::where('issuer', $user['id'])->where('issuer_type', $type)
                ->order('hits desc')
                ->all();
        }else{
            $fruits = FruitModel::where('issuer', $user['id'])->where('issuer_type', $type)
                ->order('hits desc')
                ->page($page, 10)
                ->all();
        }
        $this->assign([
            'fruits' => $fruits,
            'page' => $page,
            'maxPage' => ceil($count/10),
            'count' => $count
        ]);

        if (is_mobile()) {
            $this->assign('maxPage',1);
            $this->assign('page',1);
            return $this->fetch('/mobile/me/my_f');
        }
        return $this->fetch('my_f');
    }

    public function requirement()
    {
        $page = $this->request->param('page');
        $page = $page ? $page : 1;
        $user = json_decode(session('userInfo'), true);
        if (isset($user['teacher_no'])) {
            $type = 0;
        } else {
            $type = 1;
        }
        $count = RequirementModel::where('issuer', $user['id'])->where('issuer_type', $type)->count();
        if (is_mobile()){
            $fruits = RequirementModel::where('issuer', $user['id'])->where('issuer_type', $type)
                ->order('hits desc')
                ->all();
        }else{
            $fruits = RequirementModel::where('issuer', $user['id'])->where('issuer_type', $type)
                ->order('hits desc')
                ->page($page, 10)
                ->all();
        }
        $this->assign([
            'requirements' => $fruits,
            'page' => $page,
            'maxPage' => ceil($count/10),
            'count' => $count
        ]);

        if (is_mobile()) {
            $this->assign('maxPage',1);
            $this->assign('page',1);
            return $this->fetch('/mobile/me/my_r');
        }

        return $this->fetch('my_r');
    }

    public function FAQ()
    {
        $questions = QuestionsModel::where('status', 1)->order('sort', 'desc')->all();
        $this->assign('questions', $questions);
        if (is_mobile()) {
            return $this->fetch('/mobile/me/FAQ');
        }
        return $this->fetch('FAQ');
    }

    public function team()
    {
        $user = json_decode(session('userInfo'), true);
        if (isset($user['teacher_no'])) {
            $team = TeamModel::where('founder', $user['id'])->find();
            if ($team) {
                $members = TeamMemberModel::where('team_id', $team['id'])->order('id', 'asc')->all();
                $this->assign('team', $team);
                $this->assign('team_members', $members);
                $this->assign('member_count', count($members));
                return $this->fetch('my_team_detail');
            } else {
                $this->assign('team', null);
                $this->assign('team_members', []);
                $this->assign('member_count', 0);
                return $this->fetch('my_team_edit');
            }
        } else {
            $this->redirect("/index");
        }
        return $this->fetch('my_team_detail');
    }

    public function saveTeam()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            $members = isset($param['members']) ? $param['members'] : [];
            $user = json_decode(session('userInfo'), true);

            $issuer_type = isset($user['teacher_no']) ? 0 : 1;

            if ($issuer_type != 0) {
                $re = [
                    'code' => 0,
                    'msg' => '只有教师身份可以创建团队'
                ];
                return json($re);
            }

            $validate = new Team();
            if (!$validate->check($param)) {
                $res['code'] = 0;
                $res['msg'] = $validate->getError();
                return $res;
            }

            $param['founder'] = $user['id'];
            $param['college'] = $user['college'];
            $record = TeamModel::where('founder', $user['id'])->find();

            if (!$record) {
                unset($param['members']);
                $result = TeamModel::insertGetId($param);
                foreach ($members as $key => $value) {
                    $members[$key]['team_id'] = $result;
                }
                TeamMemberModel::insertAll($members);

                if ($result !== false) {
                    $re = [
                        'code' => 0,
                        'msg' => '创建成功'
                    ];
                    return json($re);
                } else {
                    $re = [
                        'code' => 1,
                        'msg' => '创建失败'
                    ];
                    return json($re);
                }
            } else {
                $id = $record['id'];
                unset($param['members']);

                foreach ($members as $key => $value) {
                    $members[$key]['team_id'] = $id;
                }

                TeamMemberModel::where('team_id', $id)->delete();

                $insertMember = TeamMemberModel::insertAll($members);

                $result = TeamModel::where('id', $id)->update($param);
                $re = [
                    'code' => 0,
                    'msg' => '修改成功'
                ];
                return json($re);
            }

        }
    }


    public function teamEdit()
    {
        $user = json_decode(session('userInfo'), true);
        if (isset($user['teacher_no'])) {
            $team = TeamModel::where('founder', $user['id'])->find();
            if ($team) {
                $members = TeamMemberModel::where('team_id', $team['id'])->order('id', 'asc')->all();
                $this->assign('team', $team);
                $this->assign('team_members', $members);
                $this->assign('member_count', count($members));
                return $this->fetch('my_team_edit');
            } else {
                $this->assign('team', null);
                $this->assign('team_members', []);
                $this->assign('member_count', 0);
                return $this->fetch('my_team_edit');
            }
        } else {
            $this->redirect("/index");
        }
    }

    public function deleteRequirement()
    {
        $id = $this->request->param('id/d');
        if ($id) {
            RequirementModel::where('id', $id)->delete();
            $this->success('删除成功');
        } else {
            $this->redirect("/index");
        }
    }

    public function collection()
    {
        $user = json_decode(session('userInfo'), true);

        if ($user && $this->checkLogin()) {
            $page = $this->request->param('page');
            $page = $page ? $page : 1;

            if (is_mobile()) {

                $p_page =  $this->request->param('p_page') ?  $this->request->param('p_page') : 1;
                    $issuer_type = isset($user['teacher_no']) ? 0 : 1;
                $p_count = Db::name('collection')->alias('c')->join('sk_teacher t', 't.id=c.cid')->where('type', 0)
                    ->where('uid', $user['id'])->where('user_type', $issuer_type)->count();

                $collection = Db::name('collection')->alias('c')->join('sk_teacher t', 't.id=c.cid')->where('type', 0)
                    ->where('uid', $user['id'])->where('user_type', $issuer_type)->field('t.*')->page($p_page,10)->all();

                foreach ($collection as $key => $value) {
                    $collection[$key]['tagList'] = explode(",", $value['tag_text']);
                }
                $this->assign('teachers', $collection);
                $this->assign('p_page', $p_page);
                $this->assign('p_count', $p_count);
                $this->assign('p_maxPage', ceil($p_count/10));


                $f_page =  $this->request->param('f_page') ?  $this->request->param('f_page') : 1;

                $f_count = Db::name('collection')->alias('c')->join('sk_fruit t', 't.id=c.cid')->where('c.type', 1)
                    ->where('uid', $user['id'])->where('user_type', $issuer_type)->count();
                $fruits = Db::name('collection')->alias('c')->join('sk_fruit t', 't.id=c.cid')->where('c.type', 1)
                    ->where('uid', $user['id'])->where('user_type', $issuer_type)->field('t.id,t.title,t.create_time,t.issuer,t.issuer_type')->page($f_page,10)->all();
                foreach ($fruits as $key => $value) {
                    $fruits[$key]['teacher'] = TeacherModel::where('id', $value['issuer'])->find();
                }
                $this->assign('fruits', $fruits);

                $this->assign('f_page', $f_page);
                $this->assign('f_count', $f_count);
                $this->assign('f_maxPage', ceil($f_count/10));

                $r_page =  $this->request->param('r_page') ?  $this->request->param('r_page') : 1;

                $r_count = Db::name('collection')->alias('c')->join('sk_requirement t', 't.id=c.cid')->join('sk_requirement_type rt', 'rt.id=t.type')->where('c.type', 2)
                    ->where('uid', $user['id'])->where('user_type', $issuer_type)->count();

                $requirements = Db::name('collection')->alias('c')->join('sk_requirement t', 't.id=c.cid')->join('sk_requirement_type rt', 'rt.id=t.type')->where('c.type', 2)
                    ->where('uid', $user['id'])->where('user_type', $issuer_type)->field('t.id,t.title,t.create_time,t.issuer,t.issuer_type,rt.name')->page($r_page,10)->all();

                foreach ($requirements as $key => $value) {
                    $requirements[$key]['user'] = $value['issuer_type'] == 0 ? TeacherModel::where('id', $value['issuer'])->find() : MemberModel::where('id', $value['issuer'])->find();
                }
                $this->assign('requirements', $requirements);



                $this->assign('r_page', $r_page);
                $this->assign('r_count', $r_count);
                $this->assign('r_maxPage', ceil($r_count/10));


                $t_page =  $this->request->param('t_page') ?  $this->request->param('t_page') : 1;

                $t_count = Db::name('collection')->alias('c')->join('sk_team t', 't.id=c.cid')->where('c.type', 4)
                    ->where('uid', $user['id'])->where('user_type', $issuer_type)->count();

                $teams = Db::name('collection')->alias('c')->join('sk_team t', 't.id=c.cid')->where('c.type', 4)
                    ->where('uid', $user['id'])->where('user_type', $issuer_type)->field('t.id,t.team_name,t.create_time,t.founder,t.founder_name,t.team_pic')->page($t_page,10)->all();
                foreach ($teams as $key => $value) {
                    $teams[$key]['user'] = TeacherModel::where('id', $value['founder'])->find();
                }


                $this->assign('teams', $teams);


                $this->assign('t_page', $t_page);
                $this->assign('t_count', $t_count);
                $this->assign('t_maxPage', ceil($t_count/10));

                return $this->fetch('/mobile/me/collection');
            }else{

                $issuer_type = isset($user['teacher_no']) ? 0 : 1;
                $count = Db::name('collection')->alias('c')->join('sk_teacher t', 't.id=c.cid')->where('type', 0)
                    ->where('uid', $user['id'])->where('user_type', $issuer_type)->field('t.*')->count();
                $collection = Db::name('collection')->alias('c')->join('sk_teacher t', 't.id=c.cid')->where('type', 0)
                    ->where('uid', $user['id'])->where('user_type', $issuer_type)->field('t.*')->page($page)->limit(10)->all();
            }



            foreach ($collection as $key => $value) {
                $collection[$key]['tagList'] = explode(",", $value['tag_text']);
            }
            $this->assign('teachers', $collection);
            $this->assign('page', $page);
            $this->assign('maxPage', ceil($count/10));

        }

        return $this->fetch('collection_p');
    }

    public function collection_f()
    {

        $user = json_decode(session('userInfo'), true);

        if ($user) {
            $page = $this->request->param('page');
            $page = $page ? $page : 1;

            $issuer_type = isset($user['teacher_no']) ? 0 : 1;
            $count = Db::name('collection')->alias('c')->join('sk_fruit t', 't.id=c.cid')->where('c.type', 1)
                ->where('uid', $user['id'])->where('user_type', $issuer_type)->field('t.id,t.title,t.create_time,t.issuer')->count();

            $collection = Db::name('collection')->alias('c')->join('sk_fruit t', 't.id=c.cid')->where('c.type', 1)
                ->where('uid', $user['id'])->where('user_type', $issuer_type)->field('t.id,t.title,t.create_time,t.issuer,t.issuer_type')->page($page)->limit(10)->all();
            foreach ($collection as $key => $value) {
                $collection[$key]['teacher'] = TeacherModel::where('id', $value['issuer'])->find();
            }
            $this->assign('fruits', $collection);
            $this->assign('page', $page);
            $this->assign('maxPage', ceil($count/10));
        }

        return $this->fetch('collection_f');
    }

    public function collection_r()
    {


        $user = json_decode(session('userInfo'), true);

        if ($user) {
            $page = $this->request->param('page');
            $page = $page ? $page : 1;


            $issuer_type = isset($user['teacher_no']) ? 0 : 1;
            $count = Db::name('collection')->alias('c')->join('sk_requirement t', 't.id=c.cid')->join('sk_requirement_type rt', 'rt.id=t.type')->where('c.type', 2)
                ->where('uid', $user['id'])->where('user_type', $issuer_type)->field('t.id,t.title,t.create_time,t.issuer,t.issuer_type,rt.name')->count();

            $issuer_type = isset($user['teacher_no']) ? 0 : 1;
            $collection = Db::name('collection')->alias('c')->join('sk_requirement t', 't.id=c.cid')->join('sk_requirement_type rt', 'rt.id=t.type')->where('c.type', 2)
                ->where('uid', $user['id'])->where('user_type', $issuer_type)->field('t.id,t.title,t.create_time,t.issuer,t.issuer_type,rt.name')->page($page)->limit(10)->all();
            foreach ($collection as $key => $value) {
                $collection[$key]['user'] = $value['issuer_type'] == 0 ? TeacherModel::where('id', $value['issuer'])->find() : MemberModel::where('id', $value['issuer'])->find();
            }
            $this->assign('requirements', $collection);
            $this->assign('page', $page);
            $this->assign('maxPage', ceil($count/10));
        }


        return $this->fetch('collection_r');
    }


    public function collection_t()
    {
        $user = json_decode(session('userInfo'), true);

        if ($user) {
            $page = $this->request->param('page');
            $page = $page ? $page : 1;


            $issuer_type = isset($user['teacher_no']) ? 0 : 1;
            $count =  Db::name('collection')->alias('c')->join('sk_team t', 't.id=c.cid')->where('c.type', 4)
                ->where('uid', $user['id'])->where('user_type', $issuer_type)->count();

            $teams = Db::name('collection')->alias('c')->join('sk_team t', 't.id=c.cid')->where('c.type', 4)
                ->where('uid', $user['id'])->where('user_type', $issuer_type)->field('t.id,t.team_name,t.create_time,t.founder,t.founder_name,t.team_pic')->all();
            foreach ($teams as $key => $value) {
                $teams[$key]['user'] = TeacherModel::where('id', $value['founder'])->find();
            }
            $this->assign('teams', $teams);
            $this->assign('page', $page);
            $this->assign('maxPage', ceil($count/10));
        }


        return $this->fetch('collection_t');
    }

    public function other()
    {
        if (is_mobile()) {
            return $this->fetch('/mobile/me/other');
        }
        return $this->fetch('other');
    }

    public function change_pwd()
    {
        return $this->fetch('/mobile/me/change_pwd');
    }

    public function change_phone()
    {
        return $this->fetch('/mobile/me/change_phone');
    }

    public function update()
    {
        if ($this->request->isPost()) {
            $user = json_decode(session('userInfo'), true);
            if ($user && isset($user['teacher_no'])) {
                TeacherModel::where('id', $user['id'])->update(['is_talents' => 1, 'update_time' => date('Y-m-d H:i:s', time())]);
                $re = [
                    'code' => 1,
                    'msg' => '更新成功'
                ];
                return json($re);
            } else {
                $re = [
                    'code' => 0,
                    'msg' => '更新失败'
                ];
                return json($re);
            }
        }
    }

    public function resetPhone()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            $user = json_decode(session('userInfo'), true);
            $isTeacher = isset($user['teacher_no']);
            if ($user) {
                $oldPhone = $param['old'];
                $phone = $param['phone'];
                $code = $param['code'];

                if (empty($phone)) {
                    $re = [
                        'code' => 0,
                        'msg' => '新手机号不能为空',
                        'user' => $user
                    ];
                    return json($re);
                }

                if ($user['phone'] != $oldPhone) {
                    $re = [
                        'code' => 0,
                        'msg' => '原手机号错误',
                        'user' => $user
                    ];
                    return json($re);
                }


                if ($isTeacher) {
                    $find = TeacherModel::where('phone', $phone)->find();
                } else {
                    $find = MemberModel::where('phone', $phone)->find();
                }
                if ($find) {
                    $re = [
                        'code' => 0,
                        'msg' => '新手机号已被占用',
                        'user' => $user
                    ];
                    return json($re);
                }
                $codeCheck = checkPhoneCode($phone, $code);
                if ($codeCheck === true) {
                    if ($isTeacher) {
                        $result = TeacherModel::where('id', $user['id'])->update(['phone' => $phone, 'update_time' => date('Y-m-d H:i:s', time())]);
                    } else {
                        $result = MemberModel::where('id', $user['id'])->update(['phone' => $phone, 'update_time' => date('Y-m-d H:i:s', time())]);
                    }
                    if ($result) {
                        $user['phone'] = $phone;
                        session('userInfo', json_encode($user));
                        $re = [
                            'code' => 1,
                            'msg' => '更新成功'
                        ];
                    } else {
                        $re = [
                            'code' => 0,
                            'msg' => '更新失败'
                        ];
                    }
                    return json($re);
                } else if ($codeCheck === -1) {
                    $re = [
                        'code' => 0,
                        'msg' => '验证码已过期'
                    ];
                    return json($re);
                } else {
                    $re = [
                        'code' => 0,
                        'msg' => '验证码输入错误'
                    ];
                    return json($re);
                }

            } else {
                $re = [
                    'code' => 0,
                    'msg' => '未登录'
                ];
                return json($re);
            }
        }
    }

    public function deleteTeam(){
        $user = json_decode(session('userInfo'), true);
        if (isset($user['teacher_no'])) {
            $team = TeamModel::where('founder', $user['id'])->find();
            if ($team){
                TeamModel::where('founder', $user['id'])->delete();
                $re = [
                    'code' => 1,
                    'msg' => '删除成功'
                ];
                return json($re);
            }else{
                $re = [
                    'code' => 0,
                    'msg' => '暂无团队'
                ];
                return json($re);
            }

        }else{
            $re = [
                'code' => 0,
                'msg' => '未登录'
            ];
            return json($re);
        }
    }
}
